from flask_restful import Resource
from app import api,auth,celery,mail
from flask import jsonify,g,request
from app.models import *
from utils import *
from tasks import *

class smsAPI(Resource):
    decorators = [auth.login_required]
    def post(self):
        content = request.json.get('content','') 
        phone = request.json.get('phone') 
        if not content:
            return jsonify({'code':10003,'msg':'请输入发送邮件内容'})
        if not phone:
            return jsonify({'code':10003,'msg':'请输入要发送的手机号码'})
        sms_data = {
            'content': content,
            'phone': phone,
          }
        task = send_async_sms.delay(sms_data)
        return jsonify({'code':200,'task_id':task.id,'msg':'添加任务成功'}) 


api.add_resource(smsAPI, '/devops/api/v1.0/sms', endpoint = 'sms')
